package top.chukongxiang.monitorservice.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.chukongxiang.monitorservice.config.SdkServerContextHolder;
import top.chukongxiang.monitorservice.model.entity.ServerConfig;
import top.chukongxiang.monitorservice.model.response.R;
import top.chukongxiang.monitorservice.service.HcNetSdkService;
import top.chukongxiang.monitorservice.service.ServerConfigService;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author 楚孔响
 * @version 1.0
 * @date 2023/11/3 13:34
 */
@RestController
@RequestMapping("device")
@RequiredArgsConstructor
public class DeviceController {

    private final ServerConfigService serverConfigService;

    private final HcNetSdkService hcNetSdkService;

    @GetMapping("list")
    public R<List<ServerConfig>> list() {
        List<ServerConfig> result = serverConfigService.list().stream().filter(serverConfig -> {
            Integer dvrType = SdkServerContextHolder.getDvrType(serverConfig.getId());
            return !Objects.equals(dvrType, 202);
        }).collect(Collectors.toList());
        return R.ok(result);
    }

    @GetMapping("startLive")
    public R<?> startLive(@RequestParam("serverId") Long serverId) {
        hcNetSdkService.play(serverId);
        return R.ok();
    }

}
